//
//  myResumeCellStrengthEdit.swift
//  DingDongZP
//
//  Created by LeMac on 16/12/20.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

import UIKit
import ReactiveCocoa

class myResumeCellStrengthEdit: UITableViewCell {

    
    dynamic var title:String = ""
    dynamic var desc:String = ""
    
    var titleLab:UILabel?
    var descTextView:UITextView?
    
    private let lingH:CGFloat = 8
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setUpFrame()
        descTextView?.text = desc
        initData()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initData() {
        
        RACObserve(self, "title").subscribeNext { [weak self] (obj) in
            
            let str = obj as? String ?? ""
            self?.titleLab?.text = str
            
        }
        
        RACObserve(self, "desc").subscribeNext { [weak self] (obj) in
            
            let str = obj as? String ?? ""
            self?.descTextView?.attributedText = String.getAttrFormString(lineH: (self?.lingH)!, text: str, font: LDFont.Font13)
        }
    }
    
    func setUpFrame() {
        
        
        selectionStyle = .None
        titleLab = UILabel.setDetailsLab("职位描述", fontSize: 14, titleColor: LDFontColor.Black, Alignment: .Left)
        descTextView = UITextView()
        descTextView?.layer.borderColor = LDGolbalColor.BgGoundGray.CGColor
        descTextView?.layer.borderWidth = 1
        descTextView?.font = LDFont.Font13
        descTextView?.textColor = LDFontColor.DeepGray
        
        descTextView?.rac_textSignal().subscribeNext({ [weak self] (obj) in
            
            guard let str = obj as? String else { return }
            self?.descTextView?.attributedText = String.getAttrFormString(lineH: (self?.lingH)!, text: str, font: LDFont.Font13)

        })
        
        addSubview(titleLab!)
        addSubview(descTextView!)
        
        titleLab?.snp_makeConstraints(closure: { (make) in
            
            make.left.equalTo(LDFrame.LineMargin_V)
            make.top.equalTo(LDFrame.LineMargin_V)
        })
        
        descTextView?.snp_makeConstraints(closure: { (make) in
            
            make.left.equalTo(LDFrame.LineMargin_V)
            make.right.equalTo(-LDFrame.LineMargin_V)
            make.top.equalTo(titleLab!.snp_bottom).offset(LDMargin_V*3)
            make.height.equalTo(180)
        })
        
    }
    
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        
        descTextView?.resignFirstResponder()
    }
}
